/**
 * api-show
 */
;!function () {
    var layer = layui.layer
        , form = layui.form;
}();
var element = layui.element;
$(function () {
    getApiParams();
    var result = $('#hid_result').val();
    $("#formatJsonDemo").html(JSON.stringify(JSON.parse(result), null, 4));

    layui.code({
        title: '请求返回结果',
        height: '350px', //请注意必须加px。如果该key不设定，则会自适应高度，且不会出现滚动条。
        about: false
    });
});

/* 请求 */
function test() {
    var map = new DataMap();
    var url = $('#url').text();
    var header = '';
    var params = '';

    $('.layui-table tr').each(function (idx, data) {
        if (idx == 0) return;
        var headerKey = '';
        var headerVal = '';
        var key = '';
        var val = '';
        $(this).children("td").each(function (i) {
            if (i == 0) {
                // console.log("第"+idx+"行第"+i+"个td的内容："+$(this).text());
                key = $(this).text();
            }
            if (i == 2) {
                var temp = $(this).text();
                if (temp == 'header') {
                    key = '';
                    headerKey = $(this).prev().prev().text();
                    headerVal = $(this).next().find('input').eq(0).val();

                }
            }
            if (i == 3) {
                // console.log("第"+idx+"行第"+i+"个td的内容："+$(this).find('input').eq(0).val());
                val = $(this).find('input').eq(0).val();
            }
        });
        if (key != "") {
            params += key + "=" + val + "&";
        }
        if (headerKey != "") {
            header += headerKey + "=" + headerVal + "&";
        }
    });
    console.log(header);
    console.log(params);


    var type = $('#sel-type').val();
    console.log(type);

    ajaxData(url, header, params, type);
}

/* 获取api参数列表 */
function getApiParams() {
    var params = {id: $('#hid_id').val()};
    $.post('/back/api/show', params, function (data) {
        if (data.status) {
            var html = template('test', data);
            document.getElementById("content").innerHTML = html;
        } else {
            document.getElementById("content").innerHTML = '';
        }
    });
}



